package com.leoblog.service.base;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import com.leoblog.dao.base.BaseDao;
import com.leoblog.domain.base.BaseDOM;
import com.leoblog.service.IBaseService;
import com.leoblog.util.GenericUtil;

/**
 * Base service interface.
 * @author LeoLeung
 *
 */
public abstract class BaseService<T extends BaseDOM, M extends BaseDao<T>> implements ApplicationContextAware, IBaseService {
	/**
	 * Get log object.
	 */
	private static final Log log = LogFactory.getLog(BaseService.class);
	
	protected Class<T> domainClass;
	
	protected Class<M> daoClass;
	
	protected T domain;
	
	protected M dao;
	
	protected ApplicationContext context;
	
	public void setApplicationContext(ApplicationContext context) throws BeansException
	{
		this.context = context;
	}
	
	@SuppressWarnings("unchecked")
	public BaseService()
	{
		domainClass = GenericUtil.getSuperClassGenricType(getClass(), 0);
		daoClass = GenericUtil.getSuperClassGenricType(getClass(), 1);
		log.info("BaseService domainClass" + domainClass);
		log.info("BaseService daoClass" + daoClass);
	}
	
	public T getDomain() {
		return domain;
	}
	public void setDomain(T domain) {
		this.domain = domain;
	}
	public M getDao() {
		return dao;
	}
	public void setDao(M dao) {
		this.dao = dao;
	}

	protected Class<T> getDomainClass() {
		return domainClass;
	}

	protected Class<M> getDaoClass() {
		return daoClass;
	}
}
